<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>
			保修信息添加
		</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="css/main.css" media="all">
		<script type="text/javascript" src="lib/loading/okLoading.js"></script>
		<script src="js/base.js"></script>
		<style>
			.imgs {
				display: none;
			}
		</style>

	</head>
	<body>

		<div class="x-body">
			<form class="layui-form layui-form-pane" action="" id="add">
				<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">


					<div class="layui-tab-content">
						<div class="layui-tab-item layui-show">
							<input type="hidden" name="id" value="">

							<div class="layui-form-item">
								<label class="layui-form-label">
									<span class='x-red'>*</span>所属小区
								</label>
								<div class="layui-input-block">
									<!-- 小区列表 -->
									<select name="community_id" id="community_id">

										<option value="0">---请选择小区---</option>
										<!-- 		<option value="1" >东湖小区</option>
										<option value="2" >金华万府</option> -->
									</select>
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">
									<span class='x-red'>*</span>报修人员
								</label>
								<div class="layui-input-block">
									<input type="text" name="uasername" autocomplete="off"
										placeholder="空制在80个汉字，160个字符以内" class="layui-input" disabled="disabled"
										value="">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">
									<span class='x-red'>*</span>设备名称
								</label>
								<div class="layui-input-block">
									<input id="shebeimingcheng" type="text" name="device_name" autocomplete="off"
										placeholder="空制在80个汉字，160个字符以内" class="layui-input" value="">
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">
									<span class='x-red'>*</span>状态
								</label>
								<div class="layui-input-block">
									<input type="radio" name="status" value="0" title="待受理">
									<div class="layui-unselect layui-form-radio layui-form-radioed"><i
											class="layui-anim layui-icon layui-anim-scaleSpring"></i>
										<div>待受理</div>
									</div>
									<input type="radio" name="status" value="1" title="已受理">
									<div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i>
										<div>已受理</div>
									</div>
									<input type="radio" name="status" value="2" title="已维修" checked="checked">
									<div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i>
										<div>已维修</div>
									</div>
								</div>
							</div>

							<div class="layui-form-item layui-form-text">
								<label class="layui-form-label">
									<span class='x-red'>*</span>报修描述
								</label>
								<div class="layui-input-block">
									<textarea id="description" placeholder="请输入内容" name="desc"
										class="layui-textarea"></textarea>
								</div>
							</div>

							<div class="layui-form-item">
								<button id="save" class="layui-btn" type="button" lay-filter="add" lay-submit="">
									保存
								</button>
							</div>
							<!--</form>-->
							<div style="height:100px;"></div>
						</div>



					</div>

				</div>
			</form>
		</div>
		<script src="lib/layui/layui.js" charset="utf-8"></script>
		<script src="js/x-layui.js" charset="utf-8"></script>
		<script src="js/jquery.min.js" charset="utf-8"></script>

		<script>
			$(function() {
				var username = "admin123";
				//var username="惜缘";
				$("input[name='uasername']").val(username);
			})
		</script>
		<script>
			layui.use(['laydate', 'element', 'layer', 'form'], function() {
				$ = layui.jquery; //jquery
				lement = layui.element(); //面包导航
				layer = layui.layer; //弹出层
				form = layui.form();
				laydate = layui.laydate; //日期插件
				okLoading.close($);
				form.render();



				//监听提交
				form.on('submit(add)', function(data) {

					var uasername = $("input[name='uasername']").val();
					var shebeimingcheng = $("input[name='device_name']").val();

					var community_id = $('#community_id option:selected').val(); //所属栏目ID
					if (community_id == "") {
						layer.msg('所属小区不能为空', {
							icon: 5,
							time: 2000
						});
						return false;
					}
					if (uasername == "") {
						layer.msg('报修人员不能为空', {
							icon: 5,
							time: 2000
						});
						return false;
					}
					if (shebeimingcheng == "") {
						layer.msg('设备名称不能为空', {
							icon: 5,
							time: 2000
						});
						return false;
					}
					var data = data.field;

					console.log(data);
					let json = {};
					json.id = null;
					json.xiaoquid = community_id;
					json.yonghuid = 1;
					json.shebeimingcheng = shebeimingcheng;
					json.state = data.status;
					json.description = data.desc;
					json.chuangjianshijian = new Date().toLocaleString().replaceAll("/","-");
					
					
					
					let url = "http://localhost:8080/wuye/BaoXiuController/Add";
					rest(url, "POST", json, function(r) {
						console.log(r);
						if (r.code == 200) {
							layer.msg(r.msg, {
								icon: 6,
								time: 2000
							}, function() {
								window.parent.location.reload();
								var index = parent.layer.getFrameIndex(window.name);
								parent.layer.close(index);
							});
							return false;
						} else {
							layer.msg(r.msg, {
								icon: 5,
								time: 2000
							});
							return false;
						}
						
					})

					// $.ajax({
					// 	type: "post",
					// 	url: "http://localhost:8080/wuye/BaoXiuController/Add",
					// 	data: data,
					// 	dataType: "json",
					// 	success: function(data) {
					// 		console.log(data);
					// 		if (data.status == 1) {
					// 			layer.msg(data.info, {
					// 				icon: 6,
					// 				time: 2000
					// 			}, function() {
					// 				window.parent.location.reload();
					// 				var index = parent.layer.getFrameIndex(window.name);
					// 				parent.layer.close(index);
					// 			});
					// 			return false;

					// 		} else {
					// 			layer.msg(data.info, {
					// 				icon: 5,
					// 				time: 2000
					// 			});
					// 			return false;
					// 		}
					// 	}

					// });

				});

			})
		</script>
		<!--栏目缩略图上传-->
		<script>
			function upload() {
				var formData = new FormData();
				formData.append('images', $('#previewImg')[0].files[0]);
				//console.log(formData);
				layer.msg('图片上传中', {
					icon: 16
				});
				$.ajax({
					type: "post",
					processData: false,
					contentType: false,
					url: "xxx",
					data: formData,
					success: function(data) {
						if (data.status == 1) {
							console.log(data.image_name);
							layer.closeAll('loading');
							//layer.msg(data.info,{icon:1,time:1000});
							$("#pimages").attr('src', data.image_name);
							$("#avatar").val(data.image_name);
							$(".imgs").show();
							return false;
						} else {
							layer.msg(data.info, {
								icon: 2,
								time: 1000
							});
						}
					}
				});
			}


			function getXiaoquList() {
				let url = "http://localhost:8080/wuye/XiaoQuController/page";
				let startTime = "1900-01-01 00:00:00";
				let endTime = "2999-12-31 23:59:59";
				let name = "";
				let pageSize = 100;
				let json = {};
				json.pageNo = 1;
				json.pageSize = pageSize;
				json.startTime = startTime;
				json.endTime = endTime;
				json.name = name;
				rest(url, "post", json, function(r) {
					let arr = r.data.data;
					if (r.code == 200) {
						let innerHTML = "";
						for (let i = 0; i < arr.length; i++) {
							let xiaoqu = arr[i];
							innerHTML = innerHTML + "<option value=\"" +
								xiaoqu.id + "\" >" + xiaoqu.mingcheng + "</option>";
						}
						document.getElementById("community_id").innerHTML = document.getElementById("community_id")
							.innerHTML + innerHTML;
					}
				});
			}
			getXiaoquList();
		</script>

	</body>
</html>